package com.project.controller;

import com.project.entity.Order;
import com.project.entity.Result;
import com.project.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    @GetMapping("/page/{pageIndex}/{pageItemCount}/{type}")
    public Result findPage(@PathVariable Integer pageIndex,@PathVariable Integer pageItemCount,@PathVariable String type) {
        if(pageItemCount == null){
            pageItemCount = 5;
        }
        Result result = new Result();
        result.success("查询成功");
        result.putData("orderList",orderService.findPage(pageIndex, pageItemCount,type));
        return result;
    }


    @GetMapping("/findAll")
    public Result findAll() {

        Result result = new Result();
        List<Order> all = orderService.findAll();
        result.success("查询全部成功");
        result.putData("orderList",all);

        return result;
    }

    @GetMapping("/findPageByTitle")
    public Result findPageByTitle(Integer pageIndex,
                                  Integer pageCount,
                                  String type,
                                  String title) {
        Result result = new Result();
        result.success("成功");
        result.putData("orderList",orderService.findPageByTitle(pageIndex, pageCount, type, title));
        return result;
    }


    //根据类型查询总记录数
    @GetMapping("/findTypeCount")
    public Result findTypeCount(String type) {

        Result result = new Result();
        int typeCount = orderService.findTypeCount(type);
        result.success("查询记录成功");
        result.putData("typeCount",typeCount);


        return result;
    }
}
